package com.example.hotel_lxy.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.bumptech.glide.Glide;
import com.example.hotel_lxy.R;
import com.example.hotel_lxy.application.ARouterPath;
import com.example.hotel_lxy.bean.BeanBean;
import com.example.hotel_lxy.bean.DataIndexBean;
import com.example.hotel_lxy.bean.ZeroSpSourceBean;
import com.example.hotel_lxy.net.Api;
import com.example.hotel_lxy.ui.dialog.DataSelectionDialog;
import com.example.hotel_lxy.utils.EmptyUtils;
import com.example.hotel_lxy.utils.JurisdictionUtils;
import com.example.hotel_lxy.utils.MyMarkerView;
import com.example.hotel_lxy.utils.SPUtils;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.google.android.material.tabs.TabLayout;
import com.ysxsoft.common_base.base.BaseActivity;
import com.ysxsoft.common_base.base.RBaseAdapter;
import com.ysxsoft.common_base.base.RViewHolder;
import com.ysxsoft.common_base.utils.JsonUtils;
import com.ysxsoft.common_base.utils.ToastUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * 数据
 */
@Route(path = "/main/DataActivity")
public class DataActivity extends BaseActivity  {
    List<String> mlist = new ArrayList<>();
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tabs_pending)
    TabLayout tabsPending;
    @BindView(R.id.demo_linechart)
    LineChart demoLinechart;
    @BindView(R.id.rv_trend_data)
    RecyclerView rvTrendData;
    @BindView(R.id.rv_banquet_type)
    RecyclerView rvBanquetType;
    @BindView(R.id.rv_banquet_office_type)
    RecyclerView rvBanquetOfficeType;
    @BindView(R.id.pie)
    PieChart pie;
    @BindView(R.id.rv_customer_type)
    RecyclerView rvCustomerType;
    @BindView(R.id.text_view)
    TextView textView;
    @BindView(R.id.line_one)
    LinearLayout lineOne;
    @BindView(R.id.line_two)
    LinearLayout lineTwo;
    @BindView(R.id.line_three)
    LinearLayout lineThree;
    @BindView(R.id.line_five)
    LinearLayout lineFive;
    @BindView(R.id.line_six)
    LinearLayout lineSix;
    @BindView(R.id.line_four)
    LinearLayout lineFour;
    @BindView(R.id.text_one_title)
    TextView textOneTitle;
    @BindView(R.id.text_one_number)
    TextView textOneNumber;
    @BindView(R.id.img_one_bg)
    ImageView imgOneBg;
    @BindView(R.id.text_two_title)
    TextView textTwoTitle;
    @BindView(R.id.text_two_number)
    TextView textTwoNumber;
    @BindView(R.id.img_two_bg)
    ImageView imgTwoBg;
    @BindView(R.id.text_three_title)
    TextView textThreeTitle;
    @BindView(R.id.text_three_number)
    TextView textThreeNumber;
    @BindView(R.id.img_three_bg)
    ImageView imgThreeBg;
    @BindView(R.id.text_four_number)
    TextView textFourNumber;
    @BindView(R.id.text_five_number)
    TextView textFiveNumber;
    @BindView(R.id.text_six_number)
    TextView textSixNumber;
    @BindView(R.id.text_line)
    TextView textLine;
    @BindView(R.id.line_rv_data)
    LinearLayout lineRvData;
    @BindView(R.id.rela_rv_data)
    RelativeLayout relaRvData;
    @BindView(R.id.line_type)
    LinearLayout lineType;
    @BindView(R.id.line2)
    LinearLayout line2;
    @BindView(R.id.text_money)
    TextView textMoney;
    @BindView(R.id.line_office)
    LinearLayout lineOffice;
    @BindView(R.id.text_year_mouth)
    TextView textYearMouth;
    @BindView(R.id.text_canshu)
    TextView textCanshu;
    @BindView(R.id.text_line_data)
    TextView textLineData;
    @BindView(R.id.text_year)
    TextView textYear;
    @BindView(R.id.text_yanhui)
    TextView textYanhui;
    @BindView(R.id.text_office)
    TextView textOffice;
    int tab_type = 0;
    List<PieEntry> list = new ArrayList<>();
    @BindView(R.id.text_kh)
    TextView textKh;
    private String year, month, manager_id,manager_zero_id;
    private boolean aBoolean=false;
    private String name1,name2;
    SimpleDateFormat myFmt_year = new SimpleDateFormat("yyyy年");
    SimpleDateFormat myFmt_month = new SimpleDateFormat("MM月");
    private int[] citys = {Color.parseColor("#15D37D"), Color.parseColor("#FB8638"), Color.parseColor("#6767FF")
            , Color.parseColor("#76B7FF"), Color.parseColor("#FFCA00")};


    public static void start() {
        ARouter.getInstance().build(ARouterPath.getDataActivity())
                .navigation();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_data;
    }

    @Override
    public void doWork() {
        super.doWork();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mlist.add("宴会数据");
        mlist.add("零点数据");
        for (String title : mlist) {
            tabsPending.addTab(tabsPending.newTab().setText(title));
        }
        textLine.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        textLine.getPaint().setAntiAlias(true);//抗锯齿
        Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
        year = c.get(Calendar.YEAR) + "";
        int i = c.get(Calendar.MONTH) + 1;
        if (i >= 10) {
            month = i + "";
        } else {
            month = "0" + i;
        }
        textYearMouth.setText(year + "年" + month + "月");
        textLineData.setText("" + year + "年" + month + "月数据看板");
        textYear.setText(year + "年" + "成交订单趋势图");
        textYanhui.setText("" + year + "年" + month + "月宴会类型统计图");
        textOffice.setText("" + year + "年" + month + "月宴会厅使用统计图");
        textKh.setText("" + year + "年" + month + "月客户来源统计图");
        showMaterialView();

        tabsPending.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int position = tab.getPosition();
                if (EmptyUtils.isNotEmpty(position)) {
                    switch (position) {
                        case 0:
                            tab_type = 0;
                            boolean saybanquetdata = JurisdictionUtils.getSaybanquetdata(DataActivity.this);
                            if (!saybanquetdata) {
                                aBoolean=true;
                                showMaterialView();
                            }else{
                                textView.setText(name1);
                            }
                            lineOne.setBackgroundDrawable(getResources().getDrawable(R.mipmap.icon_yd));
                            lineTwo.setBackgroundDrawable(getResources().getDrawable(R.mipmap.icon_jd));
                            lineThree.setBackgroundDrawable(getResources().getDrawable(R.mipmap.icon_qk_dd));
                            textOneTitle.setText("预订订单");
                            textTwoTitle.setText("结单订单");
                            textThreeTitle.setText("潜客订单");
                            Glide.with(DataActivity.this).load(R.mipmap.icon_data_yd).into(imgOneBg);
                            Glide.with(DataActivity.this).load(R.mipmap.icon_data_jd).into(imgTwoBg);
                            Glide.with(DataActivity.this).load(R.mipmap.icon_data_qk).into(imgThreeBg);
                            textLine.setText("趋势图");
                            textLine.setTextColor(getResources().getColor(R.color.color_4E73EB));
                            lineFour.setVisibility(View.VISIBLE);
                            lineFive.setVisibility(View.VISIBLE);
                            lineSix.setVisibility(View.VISIBLE);
                            lineRvData.setVisibility(View.VISIBLE);
                            relaRvData.setVisibility(View.VISIBLE);
                            lineType.setVisibility(View.VISIBLE);
                            line2.setVisibility(View.VISIBLE);
                            textMoney.setVisibility(View.VISIBLE);
                            lineOffice.setVisibility(View.VISIBLE);
                            demoLinechart.setVisibility(View.GONE);
                            textLine.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
                            textLine.getPaint().setAntiAlias(true);//抗锯齿
                            showindex(year, month, manager_id);
                            break;
                        case 1:
                            tab_type = 1;
                            boolean sayzerodata = JurisdictionUtils.getSayzerodata(DataActivity.this);
                            if (!sayzerodata) {
                                aBoolean=true;
                                showMaterialView();
                            }else{
                                textView.setText(name2);
                            }
                            lineOne.setBackgroundDrawable(getResources().getDrawable(R.mipmap.icon_data_jdje));
                            lineTwo.setBackgroundDrawable(getResources().getDrawable(R.mipmap.icon_qk_dd));
                            lineThree.setBackgroundDrawable(getResources().getDrawable(R.mipmap.icon_jd));
                            textOneTitle.setText("预订单数");
                            textTwoTitle.setText("有效预订数");
                            textThreeTitle.setText("翻台次数");
                            Glide.with(DataActivity.this).load(R.mipmap.icon_data_td_img).into(imgOneBg);
                            Glide.with(DataActivity.this).load(R.mipmap.icon_data_yd).into(imgTwoBg);
                            Glide.with(DataActivity.this).load(R.mipmap.icon_data_qk).into(imgThreeBg);
                            textLine.setText("注：有效预订订单=入座订单");
                            textLine.setTextColor(getResources().getColor(R.color.color_5B5B5B));
                            lineRvData.setVisibility(View.GONE);
                            relaRvData.setVisibility(View.GONE);
                            demoLinechart.setVisibility(View.VISIBLE);
                            lineType.setVisibility(View.GONE);
                            lineFour.setVisibility(View.GONE);
                            lineFive.setVisibility(View.GONE);
                            lineSix.setVisibility(View.GONE);
                            line2.setVisibility(View.GONE);
                            textMoney.setVisibility(View.GONE);
                            lineOffice.setVisibility(View.GONE);
                            textLine.getPaint().setFlags(0);
                            showZero(year, month, manager_zero_id);

                            break;
                    }
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });


    }

    private void showZero(String year, String month, String manager_id) {
        OkHttpUtils.post()
                .url(Api.POST_MATERIAL_ZERT)
                .addHeader("flag", SPUtils.get(mContext, "token", "").toString())
                .addParams("year", year)
                .addParams("month", month)
                .addParams("manager_id", manager_id)
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "零点数据onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "零点数据onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(mContext, "token", "");
                            Intent intent = new Intent(mContext, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }

                        if (beanBean.getCode().equals("0")) {
                            DataIndexBean dataIndexBean = JsonUtils.parseByGson(response, DataIndexBean.class);
                            DataIndexBean.DataBean data = dataIndexBean.getData();
                            textOneNumber.setText(data.getScheduled() + "");
                            textTwoNumber.setText("" + data.getEffective());
                            textThreeNumber.setText("" + data.getOverturn());
                            List<DataIndexBean.DataBean.TrendBean> trend = dataIndexBean.getData().getTrend();
                            List<DataIndexBean.DataBean.SourcesBean> sources = dataIndexBean.getData().getSources();
                            setchartData(demoLinechart, trend);//趋势图
                            showRvDate(trend);//趋势图列表
                            showDateCustomer(sources);//客户来源类表
                            showDateOffice(sources);//饼型图
                        }
                    }
                });
    }

    //宴会数据
    private void showindex(String year, String month, String manager_id) {
        OkHttpUtils.post()
                .url(Api.POST_MATERIAL_INDEX)
                .addHeader("flag", SPUtils.get(mContext, "token", "").toString())
                .addParams("year", year)
                .addParams("month", month)
                .addParams("manager_id", manager_id)
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "宴会数据onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "宴会数据onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(mContext, "token", "");
                            Intent intent = new Intent(mContext, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }


                        if (beanBean.getCode().equals("0")) {
                            DataIndexBean dataIndexBean = JsonUtils.parseByGson(response, DataIndexBean.class);
                            DataIndexBean.DataBean data = dataIndexBean.getData();
                            textOneNumber.setText(data.getScheduled() + "");
                            textTwoNumber.setText("" + data.getCheck());
                            textThreeNumber.setText("" + data.getSubmersible());
                            textFourNumber.setText("" + data.getDeposit());
                            textFiveNumber.setText("" + data.getCheck_money());
                            textSixNumber.setText("" + data.getRetired());
                            List<DataIndexBean.DataBean.TrendBean> trend = dataIndexBean.getData().getTrend();
                            List<DataIndexBean.DataBean.BanquetTypeBean> banquet_type = dataIndexBean.getData().getBanquet_type();
                            List<DataIndexBean.DataBean.BanquetBean> banquet = dataIndexBean.getData().getBanquet();
                            List<DataIndexBean.DataBean.SourcesBean> sources = dataIndexBean.getData().getSources();
                            setchartData(demoLinechart, trend);//趋势图
                            showRvDate(trend);//趋势图列表
                            showRvBanquetType(banquet_type);//宴会类型
                            showRvBanquetOfficeType(banquet);//宴会厅
                            showDateCustomer(sources);//客户来源类表
                            showDateOffice(sources);//饼型图
                        }
                    }
                });
    }

    //客户经理
    private void showMaterialView() {
        OkHttpUtils.post()
                .url(Api.POST_ZERO_VIEW)
                .addHeader("flag", SPUtils.get(mContext, "token", "").toString())
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "客户来源onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "客户来源onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(mContext, "token", "");
                            Intent intent = new Intent(mContext, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        ZeroSpSourceBean zeroSpSourceBean = JsonUtils.parseByGson(response, ZeroSpSourceBean.class);
                        if (beanBean.getCode().equals("0")) {
                            String string = SPUtils.get(DataActivity.this, "id", "").toString();
                            List<ZeroSpSourceBean.DataBean.ListBean> list = zeroSpSourceBean.getData().getList();
                            for (int i = 0; i < list.size(); i++) {
                                if (string.equals("" + list.get(i).getId())) {
                                    if (zeroSpSourceBean.getData().getList().get(i).getName() != null) {
                                        if(aBoolean){
                                            if(tab_type==0){
                                                manager_id = zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                                name1=zeroSpSourceBean.getData().getList().get(i).getName();
                                            }else{
                                                manager_zero_id= zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                                name2=zeroSpSourceBean.getData().getList().get(i).getName();
                                            }
                                        }else{
                                            name1=zeroSpSourceBean.getData().getList().get(i).getName();
                                            name2=zeroSpSourceBean.getData().getList().get(i).getName();
                                            manager_id = zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                            manager_zero_id= zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                        }
                                        textView.setText("" + zeroSpSourceBean.getData().getList().get(i).getName());
                                    } else {
                                        if(aBoolean){
                                            if(tab_type==0){
                                                manager_id = zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                                name1=zeroSpSourceBean.getData().getList().get(i).getUsername();
                                            }else{
                                                manager_zero_id= zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                                name2=zeroSpSourceBean.getData().getList().get(i).getUsername();
                                            }
                                        }else{
                                            name1=zeroSpSourceBean.getData().getList().get(i).getUsername();
                                            name2=zeroSpSourceBean.getData().getList().get(i).getUsername();
                                            manager_id = zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                            manager_zero_id= zeroSpSourceBean.getData().getList().get(i).getId() + "";
                                        }

                                        textView.setText("" + zeroSpSourceBean.getData().getList().get(i).getUsername());
                                    }
                                    break;
                                }
                            }
                            if(tab_type==0){
                                showindex(year, month, manager_id);
                            }else{
                                showindex(year, month, manager_zero_id);
                            }

//                            showZero(year, month, manager_id);
                        }
                    }
                });
    }

    //客户来源数据图
    private void showDateCustomer(List<DataIndexBean.DataBean.SourcesBean> sources) {
        rvCustomerType.setLayoutManager(new LinearLayoutManager(this));
        RBaseAdapter<DataIndexBean.DataBean.SourcesBean> rBaseAdapter = new RBaseAdapter<DataIndexBean.DataBean.SourcesBean>(this,
                R.layout.item_data_office_activity, sources) {
            @Override
            protected void fillItem(RViewHolder holder, DataIndexBean.DataBean.SourcesBean item, int position) {
                TextView text_type = holder.itemView.findViewById(R.id.text_type);
                TextView name = holder.itemView.findViewById(R.id.name);
                TextView source_count = holder.itemView.findViewById(R.id.source_count);
                TextView source_counts = holder.itemView.findViewById(R.id.source_counts);
                name.setText("" + item.getName());
                source_count.setText("" + item.getSource_count());
                source_counts.setText("" + item.getSource_counts());
                if (position % 5 == 0) {
                    text_type.setText("" + (position + 1));
                    text_type.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_radius5_15b37d));

                } else if (position % 5 == 1) {
                    text_type.setText("" + (position + 1));
                    text_type.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_radius5_fb8638));

                } else if (position % 5 == 2) {
                    text_type.setText("" + (position + 1));
                    text_type.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_radius5_6767ff));
                } else if (position % 5 == 3) {
                    text_type.setText("" + (position + 1));
                    text_type.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_radius5_76b7ff));
                } else if (position % 5 == 4) {
                    text_type.setText("" + (position + 1));
                    text_type.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_radius5_ffca00));
                }

            }

            @Override
            protected int getViewType(DataIndexBean.DataBean.SourcesBean item, int position) {
                return 0;
            }
        };
        rvCustomerType.setAdapter(rBaseAdapter);
    }

    //客户来源统计图
    private void showDateOffice(List<DataIndexBean.DataBean.SourcesBean> sources) {
        list.clear();
        pie.setEnabled(true);
        int j = 0;
        float f;

        for (int i = 0; i < sources.size(); i++) {
            int source_counts1 = sources.get(i).getSource_count();
            j = j + source_counts1;
        }
        for (int i = 0; i < sources.size(); i++) {
            int source_counts2 = sources.get(i).getSource_count();
            if (j == 0) {
                f = 0;
            } else {
                f = (float) source_counts2 / j * 100;
            }
            Log.e("TAG", ((int) f) + "");
            DecimalFormat decimalFormat = new DecimalFormat("00.0");//构造方法的字符格式这里如果小数不足2位,会以0补足.
            String resultString = decimalFormat.format(f);//format 返回的是字符串
            Float aFloat = Float.valueOf(resultString);
            list.add(new PieEntry(aFloat, sources.get(i).getName()));
        }
        PieDataSet pieDataSet = new PieDataSet(list, "");
        pieDataSet.setValueFormatter(new DefaultValueFormatter(2));
        pieDataSet.setDrawValues(true);
        pieDataSet.setSliceSpace(2f);
        pieDataSet.setSelectionShift(5f);
        pie.highlightValues(null);

        PieData pieData = new PieData(pieDataSet);
        pieData.setValueFormatter(new PercentFormatter());
        pie.setData(pieData);
        pie.setUsePercentValues(true);
        pie.setBackgroundColor(Color.WHITE);
        pie.setDragDecelerationFrictionCoef(0.95f);
        //设置各个数据的颜色
        int[] citysCol = new int[list.size()];
        for (int n = 0; n < list.size(); n++) {
            citysCol[n] = citys[n % 5];
        }
        pieDataSet.setColors(citysCol);
        pie.setMaxAngle(360);
        //实体扇形的空心圆的半径   设置成0时就是一个圆 而不是一个环
        pie.setHoleRadius(55);
        //中间半透明白色圆的半径    设置成0时就是隐藏
        pie.setTransparentCircleRadius(55);
        //设置中心圆的颜色
        pie.setHoleColor(Color.WHITE);
        //设置中心部分的字  （一般中间白色圆不隐藏的情况下才设置）
        pie.setCenterText("" + j);
        //设置中心字的字体颜色
        pie.setCenterTextColor(R.color.baseColorBlack);
        //设置中心字的字体大小
        pie.setCenterTextSize(15);
        //设置描述的字体大小（图中的  男性  女性）
        pie.setEntryLabelTextSize(10);
        pie.setEntryLabelColor(R.color.baseColorBlack);
        pie.setExtraOffsets(0f, 20f, 0f, 20f);

        //设置数据的字体大小  （图中的  44     56）
        pieDataSet.setValueTextSize(14);

        //设置描述的位置
        pieDataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
        pieDataSet.setValueLinePart1Length(0.3f);//设置描述连接线长度
        //设置数据的位置
        pieDataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
        pieDataSet.setValueLinePart2Length(0.3f);//设置数据连接线长度
        //设置两根连接线的颜色
        pieDataSet.setValueLineColor(R.color.color_BFBFBF);
        //对于右下角一串字母的操作

        pie.getDescription().setEnabled(false);                  //是否显示右下角描述
        pie.getDescription().setText("");    //修改右下角字母的显示
        pie.getDescription().setTextSize(20);                    //字体大小
        pie.getDescription().setTextColor(Color.RED);             //字体颜色


        //图例
        Legend legend = pie.getLegend();
        legend.setEnabled(false);    //是否显示图例
        legend.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);    //图例的位置
        //数据更新
        pie.notifyDataSetChanged();
        pie.invalidate();
    }

    //趋势图
    private void setchartData(LineChart chart, List<DataIndexBean.DataBean.TrendBean> trend) {
        List<Entry> entries = new ArrayList<>();
        List<Entry> entries1 = new ArrayList<>();
        for (int i = 0; i < trend.size(); i++) {
            entries.add(new Entry(i, trend.get(i).getNum()));
            entries1.add(new Entry(i, trend.get(i).getCounum()));
        }
        chart.setDragEnabled(true);
        chart.setTouchEnabled(true);
//        chart.setScaleEnabled(true);
        LineDataSet dataSet = new LineDataSet(entries, ""); // add entries to dataset
        LineDataSet dataSet1 = new LineDataSet(entries1, ""); // add entries to dataset

        dataSet.setColor(R.color.color_C30CBF);//线条颜色
        dataSet.setDrawValues(false);
        // 设置是否显示数据点的值
        dataSet.setDrawCircleHole(false);
        dataSet.setCircleRadius(15);//设置圆点半径大小// 设置数据点是空心还是实心，默认空心
        dataSet.setCircleColor(R.color.color_C30CBF);              // 设置数据点的颜色
        dataSet.setCircleSize(2);                         // 设置数据点的大小// 设置点击时高亮的点的颜色
        dataSet.setLineWidth(2f);//线条宽度
        dataSet.setDrawFilled(true);//是否绘制折线下方的填充
        dataSet.setFillColor(R.color.color_EEEBF6);

        dataSet1.setColor(R.color.color_387DC1);//线条颜色
        dataSet1.setDrawValues(false);
        // 设置是否显示数据点的值
        dataSet1.setDrawCircleHole(false);
        dataSet1.setCircleRadius(15);//设置圆点半径大小// 设置数据点是空心还是实心，默认空心
        dataSet1.setCircleColor(R.color.color_387DC1);              // 设置数据点的颜色
        dataSet1.setCircleSize(2);                         // 设置数据点的大小// 设置点击时高亮的点的颜色
        dataSet1.setLineWidth(2f);//线条宽度
        dataSet1.setDrawFilled(true);//是否绘制折线下方的填充
        dataSet1.setFillColor(R.color.color_E3E3E3);


        chart.setDrawGridBackground(false);



        //点击图表坐标监听
        chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onValueSelected(Entry e, Highlight h) {
                //查看覆盖物是否被回收

                    //重新绑定覆盖物
                    createMakerView(trend);
                    //并且手动高亮覆盖物
                    chart.highlightValue(h);

            }

            @Override
            public void onNothingSelected() {

            }
        });


        //设置样式
        YAxis rightAxis = chart.getAxisRight();
        //设置图表右边的y轴禁用
        rightAxis.setEnabled(false);
        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.setDrawAxisLine(false);//是否绘制靠近y轴的第一条线，设置xAxis.setDrawGridLines(false)才有效果
        leftAxis.setAxisLineWidth(2);//设置靠近y轴的第一条线的宽度
        leftAxis.setAxisLineWidth(R.color.baseColorBlack);//设置靠近y轴的第一条线的颜色
        leftAxis.setYOffset(1);
        //设置图表左边的y轴禁用
        leftAxis.setEnabled(true);
        leftAxis.setTextColor(Color.parseColor("#333333"));
        //设置x轴
        XAxis xAxis = chart.getXAxis();

        xAxis.setTextColor(Color.parseColor("#333333"));
        xAxis.setTextSize(11f);
        xAxis.setAxisMinimum(0f);
        xAxis.setDrawAxisLine(false);//是否绘制轴线
        xAxis.setDrawGridLines(true);//设置x轴上每个点对应的线
        xAxis.setDrawLabels(true);//绘制标签  指x轴上的对应数值
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置x轴的显示位置
        xAxis.setGranularity(1f);//禁止放大后x轴标签重绘
        final String weeks[] = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
        xAxis.setLabelCount(weeks.length);//设置数量


        xAxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return weeks[(int) value];
            }
        });

        //透明化图例
        Legend legend = chart.getLegend();
        legend.setForm(Legend.LegendForm.NONE);
        legend.setTextColor(Color.WHITE);
        //隐藏x轴描述
        Description description = new Description();
        description.setEnabled(false);
        chart.setDescription(description);


        LineData lineData = new LineData(dataSet, dataSet1);
        lineData.setHighlightEnabled(true);

        chart.setData(lineData);

        chart.invalidate(); // refresh
    }

    private void createMakerView(List<DataIndexBean.DataBean.TrendBean> trend) {
        MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view,trend);
        // Set the marker to the chart
        mv.setChartView(demoLinechart);
        demoLinechart.setMarker(mv);

    }

    //宴会厅使用统计图
    private void showRvBanquetOfficeType(List<DataIndexBean.DataBean.BanquetBean> banquet) {

        rvBanquetOfficeType.setLayoutManager(new LinearLayoutManager(this));
        RBaseAdapter<DataIndexBean.DataBean.BanquetBean> rBaseAdapter = new RBaseAdapter<DataIndexBean.DataBean.BanquetBean>(
                this, R.layout.item_data_banquet_office, banquet) {
            @Override
            protected void fillItem(RViewHolder holder, DataIndexBean.DataBean.BanquetBean item, int position) {
                TextView text_number = holder.itemView.findViewById(R.id.text_number);
                TextView text_type = holder.itemView.findViewById(R.id.text_type);
                ProgressBar progress = holder.itemView.findViewById(R.id.progress);
                if (position == 0) {
                    progress.setMax(item.getBanquet_count());
                }
                int i = position + 1;
                text_number.setText(i + "");

                text_type.setText(item.getName() + " " + item.getBanquet_count() + "场");
                progress.setProgress(item.getBanquet_count());

            }

            @Override
            protected int getViewType(DataIndexBean.DataBean.BanquetBean item, int position) {
                return 0;
            }
        };
        rvBanquetOfficeType.setAdapter(rBaseAdapter);
    }

    //宴会类型统计图
    private void showRvBanquetType(List<DataIndexBean.DataBean.BanquetTypeBean> banquet_type) {
        rvBanquetType.setLayoutManager(new LinearLayoutManager(this));
        RBaseAdapter<DataIndexBean.DataBean.BanquetTypeBean> rBaseAdapter = new RBaseAdapter<DataIndexBean.DataBean.BanquetTypeBean>(
                this, R.layout.item_data_banquet, banquet_type) {
            @Override
            protected void fillItem(RViewHolder holder, DataIndexBean.DataBean.BanquetTypeBean item, int position) {
                TextView text_number = holder.itemView.findViewById(R.id.text_number);
                TextView text_type = holder.itemView.findViewById(R.id.text_type);
                ProgressBar progress = holder.itemView.findViewById(R.id.progress);
                if (position == 0) {
                    progress.setMax(item.getType_count());
                }
                int i = position + 1;
                text_number.setText(i + "");
                text_type.setText(item.getName() + " " + item.getType_count() + "场");
                progress.setProgress(item.getType_count());
            }

            @Override
            protected int getViewType(DataIndexBean.DataBean.BanquetTypeBean item, int position) {
                return 0;
            }
        };
        rvBanquetType.setAdapter(rBaseAdapter);
    }

    //趋势图列表
    private void showRvDate(List<DataIndexBean.DataBean.TrendBean> trend) {
        rvTrendData.setLayoutManager(new LinearLayoutManager(DataActivity.this));
        RBaseAdapter<DataIndexBean.DataBean.TrendBean> rBaseAdapter = new RBaseAdapter<DataIndexBean.DataBean.TrendBean>(DataActivity.this,
                R.layout.item_data_activity, trend) {
            @Override
            protected void fillItem(RViewHolder holder, DataIndexBean.DataBean.TrendBean item, int position) {
                TextView text_date = holder.itemView.findViewById(R.id.text_date);
                TextView text_dd_number = holder.itemView.findViewById(R.id.text_dd_number);
                TextView text_jd_number = holder.itemView.findViewById(R.id.text_jd_number);
                text_date.setText(item.getMonth() + "");
                text_dd_number.setText("" + item.getNum());
                text_jd_number.setText("" + item.getCounum());
            }

            @Override
            protected int getViewType(DataIndexBean.DataBean.TrendBean item, int position) {
                return 0;
            }
        };
        rvTrendData.setAdapter(rBaseAdapter);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.text_view, R.id.text_line, R.id.text_year_mouth})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_view://客户经理
                if (tab_type == 0) {//宴会
                    boolean saybanquetdata = JurisdictionUtils.getSaybanquetdata(DataActivity.this);
                    if (!saybanquetdata) {
                        ToastUtils.longToast(DataActivity.this, "当前账号没有操作权限哦");
                        return;
                    }
                } else {//零点
                    boolean sayzerodata = JurisdictionUtils.getSayzerodata(DataActivity.this);
                    if (!sayzerodata) {
                        ToastUtils.longToast(DataActivity.this, "当前账号没有操作权限哦");
                        return;
                    }
                }
                DataSelectionDialog.show(DataActivity.this, null, Api.POST_ZERO_VIEW).setListener(new DataSelectionDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String name) {
                        textView.setText("" + name);
                        if(tab_type==0){
                            name1=name;
                            manager_id = id;
                        }else{
                            name2=name;
                            manager_zero_id= id;
                        }
                        if (tab_type == 0) {
                            showindex(year, month, manager_id);
                        } else {
                            showZero(year, month, manager_zero_id);
                        }
                    }
                });
                break;
            case R.id.text_line:
                if (textLine.getText().toString().equals("详细数据")) {
                    demoLinechart.setVisibility(View.GONE);
                    lineRvData.setVisibility(View.VISIBLE);
                    relaRvData.setVisibility(View.VISIBLE);
                    textCanshu.setVisibility(View.GONE);
                    textLine.setText("趋势图");
                } else if (textLine.getText().toString().equals("趋势图")) {
                    textCanshu.setVisibility(View.VISIBLE);
                    demoLinechart.setVisibility(View.VISIBLE);
                    lineRvData.setVisibility(View.GONE);
                    relaRvData.setVisibility(View.GONE);
                    textLine.setText("详细数据");
                }
                break;
            case R.id.text_year_mouth:
                initTimePicker1();
                break;

        }
    }

    private void initTimePicker1() {

        Calendar selectedDate = Calendar.getInstance();//用来设置默认选中的日期

        Calendar startDate = Calendar.getInstance();
        startDate.set(1900, 1, 1);//用来设置起始日期

        Calendar endDate = Calendar.getInstance();
        endDate.set(2100, 1, 1);//用来设置终止日期

        //时间选择器
        TimePickerView pvTime1 = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                year = myFmt_year.format(date);
                month = myFmt_month.format(date);
                textYearMouth.setText((year + "" + month));
                if (tab_type == 0) {
                    showindex(year.replace("年",""), month.replace("月",""), manager_id);
                } else {
                    showZero(year.replace("年",""), month.replace("月",""), manager_id);
                }
                textLineData.setText("" + year + "年" + month + "数据看板");
                textYear.setText(year + "年" + "成交订单趋势图");
                textYanhui.setText("" + year + "年" + month + "宴会类型统计图");
                textOffice.setText("" + year + "年" + month + "宴会厅使用统计图");
            }
        }).setType(new boolean[]{true, true, false, false, false, false})//年月日时分秒是否显示，默认全部显示，当然可以按照上一段代码分别设置是否显示年月日时分秒
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("确认")//确认按钮文字
                .setTitleSize(18)//标题文字大小
                .setTitleText("选择日期")//标题文字
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(true)//是否循环滚动
                .setTitleColor(0xFF333333)//标题文字颜色
                .setSubmitColor(0xFF333333)//确定按钮文字颜色
                .setCancelColor(0xFF333333)//取消按钮文字颜色
                .setTitleBgColor(0xFFffffff)//标题背景颜色 Night mode
                .setBgColor(0xFFffffff)//滚轮背景颜色 Night mode
                .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(startDate, endDate)//起始终止年月日设定
                .setLabel("年", "月", "", "", "", "")
                .isDialog(false)//是否显示为对话框样式
                .build();
        pvTime1.show();
    }


}